import {combineReducers} from 'redux'

const files = require.context('../pages', true, /store\.js$/)

let reducers = files.keys().reduce((temp, path) => {
  let module = (path.match(/^\.\/(\w+)(?=(\/store\.js))/) || [])[1]
  if(module) {
    module = module.toLowerCase()
    return {
      ...temp,
      [module]: files(path).default
    }
  }
  return temp
}, {})

export default combineReducers(reducers)
